<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./react/react.development.js"></script>
    <script src="./react/react-dom.development.js"></script>
    <script src="./react/babel.min.js"></script>
    <script src="./react/prop-types.js"></script>
    <script src="./react/lodash.min.js"></script>
    <script src="./react/immutable.min.js"></script>

</head>
<body>
<div id="app"></div>
<script type="text/babel">

    let app = document.querySelector('#app');

    let root = ReactDOM.createRoot(app);

    class Welcome extends React.Component {
        state = {
            msg: 'hello world'
        }
        constructor(props){
            super(props);
            console.log('constructor');
        }
        componentDidMount = () => {
            // react中发起ajax请求的初始操作，在这个钩子中完成
            console.log('componentDidMount');
        }
        componentDidUpdate = () => {
            // 等DOM更新后触发的钩子
            console.log('componentDidUpdate');
        }
        componentWillUnmount = () => {
            console.log('componentWillUnmount');
        }
        handleClick = () => {
            /* this.setState({
              msg: 'hi react'
            }); */

            //this.forceUpdate();

            root.unmount();   // 触发卸载组件
        }
        render(){
            console.log('render');
            return (
                <div>
                    <button onClick={this.handleClick}>点击</button>
                    { this.state.msg }
                </div>
            );
        }
    }
    let element = (
        <Welcome />
    );

    root.render(element);


</script>
</body>
</html>